<template>
  <div class="intro brightness" >
    <div v-if="!istips">
      <p>分享链接给好友</p>
      <div class="link" v-html="url"></div>
      <div class="btn">
        <span ref="btn" class="submit" :data-clipboard-text="url">
          一键复制
        </span>
      </div>
      <img
        class="close"
        @click.stop="$emit('close')"
        :src="require('@/assets/images/close.png')"
      />
    </div>

    <transition name="fade">
      <div class="tips" v-if="istips">
        场景链接复制成功
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  methods: {
    handleoutside() {
      this.$emit("close");
    },
  },
  mounted() {
    let copy = new window.ClipboardJS(this.$refs.btn);
    copy.on("success", (e) => {
      this.istips = true
      setTimeout(() => {
        this.istips = false
        this.$emit('close')
      }, 3000);
      e.clearSelection();
    });
    copy.on("error", (err) => console.log(err));
  },
  data() {
    return {
      url: window.location.href.replace('http://','https://'),
      istips:false
    };
  }
};
</script>

<style lang="less" scoped>
@bx: 0 3px 6px rgba(0, 0, 0, 1);
@bc: rgba(12, 91, 246, 0.8);
@animation: 0.3s ease all;
@color:#000;

.intro {
  text-align: center;
  width: 100%;
  height: 100%;
  position: fixed;
  z-index: 999;
  top: 0;
  left: 0;
  background: linear-gradient(180deg, rgba(0, 33, 75, 0.84) 0%, rgba(35, 78, 216, 0.84) 100%);
  > div {
    padding: 20px;
    width: 640px;
    transform: translate(-50%, -50%);
    top: 50%;
    left: 50%;
    position: fixed;
    background-color: rgba(27, 27, 27, 0.9);
    border-radius: 5px;
    color:#fff;
    box-sizing: content-box;
    > p {
      text-align: left;
    }
    .link {
      color: #fff;
      text-align: center;
      padding: 30px 20px;
      word-wrap: break-word;
      width: 100%;
      margin: 50px auto;
    }

    .btn{
      width: 100%;
      display: flex;
      justify-content: space-around;
      align-items: center;
      margin-bottom: 20px;
      >span{
        background: linear-gradient(180deg, #00D3F6 0%, #234ED8 100%);
        border-radius: 32px;
        width: 250px;
        height: 64px;
        line-height: 64px;
        cursor: pointer;
        font-size: 24px;
        border: 1px solid #fff;
        display: inline-block;
      }
    }

    .close {
      position: absolute;
      top: 14px;
      width: 50px;
      height: 50px;
      right: -10px;
      transform: translateX(-50%);
      border-radius: 30px;
      cursor: pointer;
    }
  }

  .tips{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 20%;
    padding: 20px 10px;
    z-index: 99999;
  }
}
@media screen and (max-width: 500px) {
  .intro {
  > div {
    padding: 20px;
    width: 80%;
    > p {
      text-align: center;
      margin-top: 40px;
      font-size: 18px;
    }
    .link {
      color: #fff;
      text-align: center;
      padding: 10px 0px;
      word-wrap: break-word;
      margin: 10px auto 30px;
    }

    .btn{
      >span{
        width: 60%;
        height: 44px;
        line-height: 44px;
        font-size: 16px;
      }

    }

    .close {
      top: 14px;
      width: 30px;
      height: 30px;
      right: 0px;
    }
  }

}
}
</style>
